package main

import (
	"fmt"
)

func main() {
	var fs = [4]func(){}

	for i:= 0; i<4; i++{
		defer fmt.Println("defer i=",i)
		defer func(){
			fmt.Println("defer_closure i = ",i)
		}()
		fs[i] = func(){
			fmt.Println("closure i = ", i)
		}
	}

	for _, f := range fs{
		f()
	}
}

func A(){
	fmt.Println("Func A")
}

func B(){
	defer func(){
		if err:=recover(); err!= nil{
			fmt.Println("Recover in B")
		}
	}()
	panic("Panic in B")
}

func C(){
	fmt.Println("Func C")
}


func closure(x int) func(int) int {
	fmt.Println("%p1\n", &x)
	return func(y int) int {
		fmt.Println("%p2\n", &x)
		return x + y
	}
}
